package com.wd.health.model.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.health.R;
import com.wd.health.model.bean.KslbBean;
import com.wd.health.view.activity.WzysActivity;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * @ProjectName:shopmall
 * @Package:com.bawei.myhealth.model.adapter
 * @ClassName:KslbAdapter
 * @UpdateUser: 裴童童
 * @date: 2020/12/8
 */
public class KslbAdapter extends RecyclerView.Adapter<KslbAdapter.ViewHolder>{
    List<KslbBean.ResultBean> list;
    Context context;

    public KslbAdapter(List<KslbBean.ResultBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(context,R.layout.layout_kslb,null));
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        holder.sdv.setImageURI(list.get(position).getPic());
        holder.tv.setText(list.get(position).getDepartmentName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(holder.itemView.getContext(), WzysActivity.class);
                intent.putExtra("id",list.get(position).getId());
                holder.itemView.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final SimpleDraweeView sdv;
        private final TextView tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            sdv = itemView.findViewById(R.id.sdv_kslb);
            tv = itemView.findViewById(R.id.tv_kslb);
        }
    }

} 
